package org.learn.java;

public class PrimeCounter {

	public void findPrimeNumbers(int n) {
		int ub = (int) Math.sqrt(n);
		boolean composites[] = new boolean[n + 1];
		for (int i = 2; i <= ub; i++) {
			if (!composites[i]) {
				for (int k = i * i; k <= n; k += i)
					composites[k] = true;
			}
		}

		for (int i = 2; i <= n; i++)
			if (!composites[i])
				System.out.print(i + " ");

	}

	public static void main(String[] args) {

		int n = Integer.parseInt(args[0]);
		PrimeCounter counter = new PrimeCounter();
		counter.findPrimeNumbers(n);

	}

}
